//
//  ViewController.m
//  RSStarRating
//
//  Created by thinkjoy on 2017/8/7.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "ViewController.h"
#import "RSShowStarView.h"


#import "CDZStarsControl.h"

@interface ViewController ()<CDZStarsControlDelegate>

@property   (nonatomic,strong)  RSShowStarView * showStarV;
@property (weak, nonatomic) IBOutlet UILabel *scoreLab;

@property (weak, nonatomic) IBOutlet UIStepper *stepper;



@property (weak, nonatomic) IBOutlet UISegmentedControl *drawStyleSegment;

@property (weak, nonatomic) IBOutlet UISegmentedControl *styleSegment;
@property (weak, nonatomic) IBOutlet UISegmentedControl *alignmentSegment;


@property (nonatomic, strong) CDZStarsControl *starsControl;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     _showStarV =   [[RSShowStarView alloc] initWithFrame:CGRectMake(20, 100, self.view.frame.size.width-40, 30) showStarStyle:RSShowStarStyleReadonly starAlignment:RSShowStarAlignmentCenter showStarDrawStyle:RSShowStarDrawStyleCompleteAndHalf starCount:5 defaultScore:3 starSpace:5 starMargin:5 starFont:30];
    _showStarV.backgroundColor   =   [UIColor lightGrayColor];
    [self.view addSubview:_showStarV];
    
    __weak __typeof__(self) weakSelf = self;
    [_showStarV  setScoreBlock:^(CGFloat score){
        weakSelf.scoreLab.text   =   [[NSString alloc] initWithFormat:@"%.2f",score];
        weakSelf.stepper.value  =   score;
    }];
    
    _scoreLab.text   =   [[NSString alloc] initWithFormat:@"%.2f",_showStarV.defaultScore];
    
    _stepper.value  =   _showStarV.defaultScore;
    _stepper.maximumValue   =   _showStarV.starCount;
    
    _drawStyleSegment.selectedSegmentIndex   =   _showStarV.showStarDrawStyle;
    _styleSegment.selectedSegmentIndex  =   _showStarV.showStarStyle;
    _alignmentSegment.selectedSegmentIndex  =   _showStarV.starAlignment;
    
    
    
    
    
    [self.view addSubview:self.starsControl];
}

- (IBAction)clickStrpper:(UIStepper *)sender {
    [_showStarV setDefaultScore:sender.value];
}

- (IBAction)clickDrawStyleSegment:(UISegmentedControl *)sender
{
    [_showStarV setShowStarDrawStyle:sender.selectedSegmentIndex];
}
- (IBAction)clickStyleSegment:(UISegmentedControl *)sender
{
    [_showStarV setShowStarStyle:sender.selectedSegmentIndex];
}
- (IBAction)clickAlignmentSegment:(UISegmentedControl *)sender
{
    [_showStarV setStarAlignment:sender.selectedSegmentIndex];
}

#pragma mark    - CDZStarsControl
- (void)starsControl:(CDZStarsControl *)starsControl didChangeScore:(CGFloat)score{
    NSLog(@"%.2f",score);
}

- (CDZStarsControl *)starsControl{
    if (!_starsControl) {
        _starsControl = [CDZStarsControl.alloc initWithFrame:CGRectMake(10, self.view.frame.size.height-50, self.view.frame.size.width - 20 , 50) stars:5 starSize:CGSizeMake(50, 50) noramlStarImage:[UIImage imageNamed:@"star_normal"] highlightedStarImage:[UIImage imageNamed:@"star_highlighted"]];
        _starsControl.delegate = self;
        _starsControl.allowFraction = YES;
        _starsControl.score = 2.6f;
    }
    return _starsControl;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
